<?php

namespace IDock\Insurance\YAIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\YAIC\YAICEnums;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllYAICResponse
{

    /*** @var VehicleModelPrinter $printer */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody();
        $modelList = $body['responseBody']['carModel']['CarModelDTO'] ?? [];
        $modelList = $this->formatArray($modelList);
        if (!$modelList) {
            return $this;
        }
        $queryModelNo = $body['responseBody']['queryModelNo'] ?? '';
        foreach ($modelList as $datum) {

            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['modelCode'] ?? '';
            $vehiclePrinter->vehicleName = $datum['modelName'] ?? '';
            $vehiclePrinter->brandName = $datum['brandCN'] ?? '';
            $vehiclePrinter->vehicleSeat = $datum['ratedPassengerCapacity'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['displacement'] ?? '0';
            $vehiclePrinter->vehicleYear = $datum['marketYear'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['replacementValue'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = $datum['replacementValue'] ?? '';
            $vehiclePrinter->energyTypeCode =  array_search($datum['fuelType'] ?? '',YAICEnums::$energyType) ?: '0' ;//能源类型
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['tonnage'] ?? 0;
            $vehiclePrinter->wholeWeight = $datum['wholeWeight'] ?? 0;
            $vehiclePrinter->power = $datum['powerScale'] ?? 0;
            $vehiclePrinter->item['queryModelNo'] = $queryModelNo;
            //
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
